<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<title></title>
<style type="text/css">
#panel_login .controls {
	padding: 0px 15px 15px !important;
}

#panel_login {
	margin-top: 100px;
}
</style>
<c:import url="../../inc.jsp" />
<script type="text/javascript">
	$(function() {

		$("#form_login").validate({
			rules : {
				'user.name' : {
					required : true,
				},
				'user.pwd' : {
					required : true
				},
				'user.companyId' : {
					required : true
				}
			},
			messages : {
				'user.name' : {
					required : '请填写登陆名称',
				},
				'user.pwd' : {
					required : '请填写密码'
				},
				'user.companyId' : {
					required : '请选择公司'
				}
			}
		});

		$('#form_login').ajaxForm({
			beforeSubmit : function(formData, jqForm, options) {
				return jqForm.validate().form();
			},
			success : function(result, statusText) {
				if (result.success) {
					new PNotify({
						text : result.info,
						type : 'success'
					});
					location.replace('${pageContext.request.contextPath}/');
				} else {
					new PNotify({
						text : result.info,
						type : 'error'
					});
				}
			},
			url : '${pageContext.request.contextPath}/global/login',
			type : 'post',
			dataType : 'json'
		});

	});
</script>
</head>
<body>
	<div class="container">
		<form action="" method="post" id="form_login">
			<div class="col-md-offset-3 col-md-6">
				<div class="panel panel-default panel-single" id="panel_login">
					<div class="panel-heading">
						<button type="button" class="btn btn-danger btn-block" onclick="location.replace('${pageContext.request.contextPath}/global/init');">初始化数据库</button>
						<table class="table">
							<thead>
								<tr>
									<th>#</th>
									<th>登录名</th>
									<th>密码</th>
									<th>公司</th>
								</tr>
							</thead>
							<tbody>
								<tr>
									<td>1</td>
									<td>sunyu</td>
									<td>123456</td>
									<td>运维</td>
								</tr>
							</tbody>
						</table>
					</div>
					<div class="panel-body">
						<div id="div_id_username" class="row">
							<div class="controls clearfix">
								<div class="input-group input-group-lg">
									<span class="input-group-addon"><i class="glyphicon glyphicon-user"></i></span><input type="text" class="form-control" placeholder="登录名" name="user.name" id="inputLoginName" />
								</div>

							</div>
						</div>
						<div id="div_id_password" class="row">
							<div class="controls clearfix">
								<div class="input-group input-group-lg">
									<span class="input-group-addon"><i class="glyphicon glyphicon-lock"></i></span><input type="password" class="form-control" placeholder="密码" name="user.pwd" id="inputPassword" />
								</div>
							</div>
						</div>
						<div id="div_id_password" class="row">
							<div class="controls clearfix">
								<div class="input-group input-group-lg">
									<span class="input-group-addon"><i class="glyphicon glyphicon-copyright-mark"></i></span><select name="user.companyId" class="form-control" id="selectCompany">
										<c:forEach items="${companys}" var="company">
											<option value="${company.id}">${company.name}</option>
										</c:forEach>
									</select>
								</div>
							</div>
						</div>
						<div class="col-md-6">
							<button type="button" class="btn btn-lg btn-info btn-block">注册</button>
						</div>
						<div class="col-md-6">
							<button type="submit" class="btn btn-lg btn-success btn-block">登录</button>
						</div>
					</div>
				</div>
			</div>
		</form>
	</div>
</body>
</html>